package com.sky.controller.admin;

import com.graphbuilder.math.func.MinFunction;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.pojo.Category;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.SetMealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@Api(tags = "套餐相关接口")
@Slf4j
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    /**
     * 添加套餐
     *
     * @param
     * @return
     */
    @PostMapping("/setmeal")
    @ApiOperation("添加套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("要添加的菜品的信息为：{}", setmealDTO);
        setMealService.addSetmeal(setmealDTO);
        return Result.success();
    }

    @ApiOperation("查询套餐类型回显 ！！不存在！！！！")
    @GetMapping("/dish/{categoryId}")
    public Result<List> selectCategoryById(@PathVariable int categoryId) {
        log.info("接受到的分类为：{}", categoryId);
        List<Category> list = setMealService.selectCategoryById(categoryId);
        return Result.success(list);
    }

    @GetMapping("/dish/list")
    @ApiOperation("添加套餐时查询单个菜品")
    public Result<List> selectDishListByCaregorlyId(String categoryId) {
        log.info("要查询的菜品categorlyId为：{}", categoryId);
        List<Dish> list = setMealService.selectDishListByCaregorlyId(categoryId);
        return Result.success(list);
    }

    @GetMapping("/setmeal/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> selectSetMealList(SetmealPageQueryDTO setmealPageQueryDTO) {
        log.info("分页查询的参数：{}", setmealPageQueryDTO);
        PageResult result = setMealService.selectSetMealList(setmealPageQueryDTO);
        return Result.success(result);
    }

    @DeleteMapping("setmeal")
    @ApiOperation("批量删除")
    public Result deleteSetMeals(@RequestParam List<Long> ids) {
        log.info("根据ids删除菜品：{}", ids);
        setMealService.deleteSetmeals(ids);
        return Result.success();
    }

    @GetMapping("/setmeal/{setmealId}")
    @ApiOperation("根据id查询回显")
    public Result<SetmealVO> seleSetmealById(@PathVariable Long setmealId) {
        log.info("要查询的的套餐id为：{}", setmealId);
        SetmealVO result = setMealService.selectSetmealById(setmealId);
        return Result.success(result);
    }

    @PutMapping("/setmeal")
    @ApiOperation("更新套餐")
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("要更新的参数为{}", setmealDTO);
        setMealService.updateSetmeal(setmealDTO);
        return Result.success();

    }

    @PostMapping("/setmeal/status/{status}")
    public Result updateSetmealStatus(@PathVariable int status,String id) {
        log.info("要修改状态的id为：{},{}",id,status);
        setMealService.updateSetmealStatus(status,id);
        return Result.success();
    }

}
